﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kaiser.Models;
using Kaiser.Modules.Cubic.DomainModel.Product;
using Kaiser.Modules.Cubic.Repositories;
using Kaiser.Modules.Cubic.ViewModel;

namespace Kaiser.Repositories.iBatis.CUBIC
{
    public class ProductCategoryRepositorie : IProductCategoryRepositorie
    {
        private IBatisHepler IBatisHepler = null;
        public ProductCategoryRepositorie()
        {
            IBatisHepler = new BatisHepler("SQLMap.CUBIC.config");
        }

        public Models.DataGrid<Modules.Cubic.DomainModel.Product.ProductCategory> SearchProductCategory(Modules.Cubic.ViewModel.ProductCategorySearch search, Models.PagingInfo pageinfo)
        {
            int totalCount = 0;

            var list = IBatisHepler.ExcuteSelectForList<ProductCategory>("ProductCategory.GetAll", search, pageinfo.Size,
                                                                         pageinfo.Index, out totalCount);

            pageinfo.TotalCount = totalCount;

            var result = new DataGrid<ProductCategory>(list,pageinfo);
            return result;
        }

        public DataGrid<ProductCategory> GetProductCategoryAll(ProductCategorySearch search, Models.PagingInfo pageinfo)
        {
            var result = new DataGrid<ProductCategory>();

            int totalCount = 0;

            result.TableResult = IBatisHepler.ExcuteSelect("ProductCategory.GetAll", search, pageinfo.Size, pageinfo.Index + 1, out totalCount);

            result.total = totalCount;

            return result;
        }

        public void Insert(ProductCategory model)
        {
            var result = IBatisHepler.ExcuteInsert("ProductCategory.Insert", model);
        }

        public void Update(ProductCategory model)
        {
            var result = IBatisHepler.ExcuteUpdate("ProductCategory.Update", model);
        }

        public int Delete(object primaryId)
        {
          return IBatisHepler.ExcuteDelete("ProductCategory.Delete", primaryId);
        }

        public ProductCategory Get(object primaryId)
        {
            var result = IBatisHepler.ExcuteSelectObj("ProductCategory.Get", primaryId) as ProductCategory;
            return result;
        }

        public int DeleteList(IList<string> ids)
        {
            var hs=new Hashtable();
            hs.Add("ids",ids);
            return IBatisHepler.ExcuteDelete("ProductCategory.DeleteList", hs);
        }


        public ProductCategory GetProductCategoryByCode(string categoryCode)
        {
            var result = IBatisHepler.ExcuteSelectObj("ProductCategory.GetByCode", categoryCode) as ProductCategory;
            return result;
        }
    }
}
